package threadtest;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author shentianyu
 * @date 2021-06-29 12:18
 */
public class MyRunnable implements Runnable{

    private static int luosi = 200;

    @Override
    public synchronized void run() {

            while(luosi>0){
                luosi--;
                System.out.println(Thread.currentThread().getName()+" 剩余螺丝的个数 "+luosi);
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
    }
}

class RunnableDemo{
    public static void main(String[] args) {

        new Thread(new MyRunnable()).start();
        System.out.println("--------");
        new Thread(new MyRunnable()).start();
        //ExecutorService executorService = Executors.newSingleThreadExecutor();
//        ExecutorService executorService = Executors.newFixedThreadPool(5);
//        executorService.submit(new MyRunnable());
//        executorService.submit(new MyRunnable());
//        executorService.shutdown();

    }
}
